#include <iostream>
#include <pthread.h>
#include <unistd.h>

class TheardArgs
{
public:
    std::string name;
    int num;
};

void *ThreadRun(void *args)
{
    TheardArgs *t = static_cast<TheardArgs *>(args);
    int cnt = 10;
    while (cnt--)
    {
        std::cout << t->name << " num is: " <<t->num++ << std::endl;
        //sleep(1);
    }

    return (void*)111;
}

int main()
{
    TheardArgs *t = new TheardArgs();
    t->name = "t_1";
    t->num = 1;
    pthread_t tid; // 线程的id
    int n = pthread_create(&tid, nullptr, ThreadRun, (void *)t);
    if (n != 0)
    {
        std::cout << "thread create failed...." << std::endl;
        return 1;
    }

    std::cout << "main thread wait begin...." << std::endl;
    void* ret = nullptr;
    n = pthread_join(tid, &ret);
    if (n != 0)
    {
        std::cout << "main thread wait failed...." << std::endl;
    }
    else
    {
        std::cout << "main thread wait success...., return code: " << (uint64_t)ret<< std::endl;
    }

    return 0;
}

// struct page
// {
//     int flag; // 是否被占用、是否是脏页、是否被绑定
//     int mode; // 权限
//     //.....
// };